package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/12/19 14:01
 * @description：https://leetcode-cn.com/problems/find-the-town-judge/
 */
public class 找到小镇的法官 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }


    class Solution {
        public int findJudge(int n, int[][] trusts) {
            int[] inDeg = new int[n + 1];
            int[] outDeg = new int[n + 1];
            for (int[] trust : trusts) {
                inDeg[trust[1]]++;
                outDeg[trust[0]]++;
            }
            for (int i = 1; i <= n; i++) {
                if (inDeg[i] == n - 1 && outDeg[i] == 0) return i;
            }
            return -1;
        }
    }
}
